package com.yungu.swift.api.route.v1.driver.h5;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.assets.driver.service.DriverCheckService;
import com.yungu.swift.constants.CommonConstant;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

import static com.yungu.swift.api.config.NacosListener.SYS_CONFIG;

/**
 * @author cuixiuyin
 * @date 2018/1/24
 */
@Controller
@RequestMapping(value = "/h5/taxiDriver")
public class TaxiDriverH5Controller {

    @Reference
    private DriverCheckService driverCheckService;

    @RequestMapping(value = {"/register"}, method = {RequestMethod.POST, RequestMethod.GET})
    public String index(@RequestParam String appid,
                        @RequestParam String agentUuid,
                        @RequestParam String companyUuid,
                        @RequestParam Integer type,
                        Model model) {
        model.addAttribute("type", type);
        model.addAttribute("appid", appid);
        model.addAttribute("agentUuid", agentUuid);
        model.addAttribute("companyUuid", companyUuid);
        return "commonPage/taxiIndex";
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST, RequestMethod.GET})
    public String add(@RequestParam String appid,
                      @RequestParam String agentUuid,
                      @RequestParam String companyUuid,
                      @RequestParam String mobile,
                      Model model) {
        model.addAttribute("mobile", mobile);
        model.addAttribute("appid", appid);
        model.addAttribute("agentUuid", agentUuid);
        model.addAttribute("companyUuid", companyUuid);
        Map<String, Object> map = new HashMap<>(8);
        map.put("mobile", mobile);
        map.put("appid", appid);
        map.put("type", CommonConstant.BUSINESS_TYPE_TAXI);
        model.addAttribute("driverCheckDto", driverCheckService.getLatest(map).getData());
        model.addAttribute("website", SYS_CONFIG.getWebSite());
        return "commonPage/taxiAdd";
    }

}
